package org.popupcommunication.service.impl;

import org.popupcommunication.dao.AgendaPersoDAO;
import org.popupcommunication.dao.UserDAO;
import org.popupcommunication.model.AgendaPerso;
import org.popupcommunication.service.AgendaPersoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.Errors;

@Transactional
public class AgendaPersoManagerBean implements AgendaPersoManager{
	private AgendaPersoDAO agendaPersoRepository;
	@Autowired  UserDAO userRepository;	

	public UserDAO getUserRepository() {
		return userRepository;
	}

	public void setUserRepository(UserDAO userRepository) {
		this.userRepository = userRepository;
	}	
	
	public AgendaPersoDAO getAgendaPersoRepository() {
		return agendaPersoRepository;
	}

	public void setAgendaPersoRepository(AgendaPersoDAO agendaPersoRepository) {
		this.agendaPersoRepository = agendaPersoRepository;
	}

	@Override
	public boolean registerAgendaPerso(AgendaPerso ap, Errors errors) {
        boolean valid = !errors.hasErrors();
        if (valid){
        	agendaPersoRepository.add(ap);     	
        }
        return valid;		
	}

	@Override
	public AgendaPerso findById(Integer id) {
		return agendaPersoRepository.findById(id);
	}

}
